package com.atcumt.bytedance;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 4
 * 1 1234
 * 2 12
 * 3 12345
 * 4 123456789
 * <p>
 * 1_2_3_4
 * 12
 * 12_345
 * 1_2345_6789
 */
public class Main06 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        while (N-- > 0) {
            int n = scanner.nextInt();
            long num = scanner.nextLong();
            List<String> list = new ArrayList<>();
            StringBuilder sb = new StringBuilder();

            long sum = 1;
            // 取出每一位存入 List,  4 3 2 1
            do {
                list.add(String.valueOf(num / sum % 10));
                sum *= 10;
            } while (sum <= num && sum > 0);

            // 从 List中取出进行操作 4_3_2_1 -> 1_2_3_4
            for (int i = 0, j = 0; i < list.size(); i++) {
                sb.append(list.get(i));
                j++;
                if (i < (list.size() - 1) && j % n == 0) {
                    sb.append("_");
                }
            }
            System.out.println(sb.reverse().toString());
        }
    }
}
